<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<html>
<form role="form" class="form-validation" id="fm" action="<%=path %>/updateGoods" method="post" enctype="multipart/form-data">
	<input type="hidden" name="goodsId" id="goodsId" value="${param.goodsId }">
		<div class="row">
			<div class="col-md-6 form-group">
				<label>商品名称:</label> <span id="goodsName"></span>
			</div>
			<div class="col-md-6 form-group">
				<label>商品类别:</label> <span id="goodsClassify"></span>
			</div>
			
		</div>
		<div class="clearfix"></div>
		<div class="row">
			<div class="col-md-6 form-group">
				<label>商品价格:</label> <span id="goodsPrice"></span>
			</div>
			<div class="col-md-6 form-group">
				<label>商品原价:</label> <span id="goodsQuondamPrice"></span>
			</div>
		</div>
		<div class="clearfix"></div>
		<div class="form-group">
			<label>商品主图</label>
			<div class="row" id="goodsMainPhotoDiv">
			</div>
		</div>
		<div class="clearfix"></div>
		<div class="form-group">
			<label>商品图片</label>
			<div class="row" id="photoDiv">
			</div>
		</div>
		<div class="clearfix"></div>
		<div class="form-group">
			<label>商品描述:</label>
			<span id="goodsIntro"></span>
		</div> 
		<div class="form-group text-center" id="btnDiv">
			
		</div>
	</form>

	<script type="text/javascript">
		$(function(){
			$.ajax({
				 type:"POST",
		         url: "<%=path %>/manager/getGoodsClassifyList",
		         success: function(data,status,xhr){
		        	 var classifyList=data;
		        	 $.ajax({
						 type:"POST",
				         url: "<%=path %>/manager/getGoodsInfo?goodsId=${param.goodsId}",
				         success: function(data,status,xhr){
				        	$('#goodsName').html(data.goodsName);
				        	for(var i=0;i<classifyList.length;i++){
				        		if(classifyList[i].cassifyId==data.classifyId1){
				        			$('#goodsClassify').html(classifyList[i].cassifyName);
				        		}
				        	 }
				        	$('#goodsPrice').html(data.goodsPrice);
				        	$('#goodsStock').html(data.goodsStock);
				        	$('#googsWeight').html(data.googsWeight);
				        	$('#goodsSize').html(data.goodsSize);
				        	$('#goodsQuondamPrice').html(data.goodsQuondamPrice);
				        	$('#goodsMainPhotoDiv').append('<div class="col-xs-6 col-md-4" id="addGoodsMainPhotoDiv"><img class="img-responsive" src="<%=path %>/manager/getGoodsPhoto?photoUrl='+data.goodsThums+'" style="position:relative">'
									+'</div>');
							var goodsImages=data.goodsImage.split(',');
							for(var i=0;i<goodsImages.length;i++){
								if(goodsImages[i]!=null&&goodsImages[i]!=''){
									$('#photoDiv').append('<div class="col-xs-6 col-md-4"><img class="img-responsive" src="<%=path %>/manager/getGoodsPhoto?photoUrl='+goodsImages[i]+'" style="position:relative">'
											+'</div>');
								}
							}
				        	$('#goodsIntro').html(data.goodsIntro);
				        	if(data.state==0){
				        		$("#btnDiv").html('<button class="btn btn-md btn-primary" type="button" onclick="openGoods()"> 打开商品 </button>&nbsp;&nbsp;&nbsp;&nbsp;');
				        	}else{
				        		$("#btnDiv").html('<button class="btn btn-md btn-primary" type="button" onclick="closeGoods()"> 关闭商品 </button>&nbsp;&nbsp;&nbsp;&nbsp;');
				        	}
				         }
					})
		         }
			})
		})
		function openGoods(){
			swal({ 
				  title: "是否确定打开此二手商品？", 
				  type: "warning",
				  showCancelButton: true, 
				  confirmButtonColor: "#DD6B55",
				  confirmButtonText: "打开商品！", 
				  cancelButtonText: "取消打开！",
				  closeOnConfirm: false, 
				  closeOnCancel: true
				},
				function(isConfirm){ 
				    if(isConfirm){
				    	$.ajax({
							 type:"POST",
					         url: "<%=path %>/manager/openGoods?goodsId=${param.goodsId}",
					         success: function(data,status,xhr){
					        	 if(data.state==1){
					        		 swal({ 
							   			  title: "提交成功", 
							   			  text: "打开成功", 
							   			  type: "success",
							   			},function(){
							        		 $("#tabId").bootstrapTable('refresh');
							        		 $('#myModal').modal('hide')
							   			});
					        		 
					        	 }else{
					        		 swal({ 
							   			  title: "提交失败", 
							   			  text: "打开失败", 
							   			  type: "error",
							   			}); 
					        	 }
					         }
						})
				    }
				});
		}
		function closeGoods(){
			swal({ 
				  title: "是否确定关闭此二手商品？", 
				  type: "warning",
				  showCancelButton: true, 
				  confirmButtonColor: "#DD6B55",
				  confirmButtonText: "关闭商品！", 
				  cancelButtonText: "取消关闭！",
				  closeOnConfirm: false, 
				  closeOnCancel: true
				},
				function(isConfirm){ 
				    if(isConfirm){
				    	$.ajax({
							 type:"POST",
					         url: "<%=path %>/manager/closeGoods?goodsId=${param.goodsId}",
					         success: function(data,status,xhr){
					        	 if(data.state==1){
					        		 swal({ 
							   			  title: "提交成功", 
							   			  text: "关闭成功", 
							   			  type: "success",
							   			},function(){
							        		 $("#tabId").bootstrapTable('refresh');
							        		 $('#myModal').modal('hide')
							   			});
					        		 
					        	 }else{
					        		 swal({ 
							   			  title: "提交失败", 
							   			  text: "关闭失败", 
							   			  type: "error",
							   			}); 
					        	 }
					         }
						})
				    }
				});
		}

		</script>
</html>